import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, confusion_matrix
import pandas as pd

df0 = pd.read_csv('data/pima_train_processed.csv')
df1 = pd.read_csv('data/pima_test_processed.csv')

X_train = df0.drop('Outcome', axis=1)
y_train = df0['Outcome']
X_test = df1.drop('Outcome', axis=1)
y_test = df1['Outcome']

model = LogisticRegression(max_iter=1000)
model.fit(X_train, y_train)

# 预测概率
y_pred_proba = model.predict_proba(X_test)[:, 1]

# 绘制逻辑回归散点图
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.figure(figsize=(10, 6))
plt.scatter(range(len(y_test)), y_pred_proba, c=y_test, cmap='bwr', alpha=0.7)
plt.colorbar(label='真实糖尿病状态 (0=否, 1=是)')
plt.xlabel('Sample Index')
plt.ylabel('预测患病率')
plt.title('糖尿病逻辑回归预测')
plt.axhline(y=0.5, color='black', linestyle='--', label='Decision Boundary (0.5)')
plt.legend()
plt.show()